package guoanmaker.provider.business.controller;

import java.math.BigDecimal;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import guoanmaker.provider.business.model.PersonalFinanceProject;
import guoanmaker.provider.business.service.PersonalFinanceProjectServiceInterface;
import guoanmaker.provider.helper.common.AjaxJson;
import guoanmaker.provider.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

/**
 * 金融服务Controller
 * @author ws
 * 2017-12-19
 */

@RestController
@RequestMapping(ApiController.PERSONAL_FINANCE_PROJECT_URL)
public class PersonalFinanceProjectController {


	@Resource
	private PersonalFinanceProjectServiceInterface personalFinanceProjectService;
	
	@ApiOperation(value="分页查询PC端个人中心金融服务", notes="分页查询PC端个人中心金融服务")
	@PostMapping("/findPersonalFinanceProjectForPCPerson")
	public AjaxJson findPersonalFinanceProjectForPCPerson(String userId, Integer page, Integer size){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectForPCPerson(userId, page, size));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="保存新建金融服务项目或修改金融服务项目的商业企划书部分", notes="保存新建金融服务项目或修改金融服务项目的商业企划书部分")
	@PostMapping("/saveOrUpdatePersonalFinanceProjectPartOne")
	public AjaxJson saveOrUpdatePersonalFinanceProjectPartOne(PersonalFinanceProject personalFinanceProject){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.saveOrUpdatePersonalFinanceProjectPartOne(personalFinanceProject));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	/**
	 * 
	 * @param personalFinanceProject
	 * @param flag1
	 * 			0:该金融项目没有专利技术    1:该金融项目有专利技术
	 * @param flag2
	 * 			0:该金融项目没有融资经历    1:该金融项目有融资经历
	 * @param flag3
	 * 			0:该金融项目没有创业赛事奖项    1:该金融项目有创业赛事奖项
	 * @return
	 */
	@ApiOperation(value="修改金融服务项目的融资信息部分", notes="修改金融服务项目的融资信息部分")
	@PostMapping("/updatePersonalFinanceProjectPartTwo")
	public AjaxJson updatePersonalFinanceProjectPartTwo(@RequestBody PersonalFinanceProject personalFinanceProject, Integer flag1, Integer flag2, Integer flag3){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.updatePersonalFinanceProjectPartTwo(personalFinanceProject, flag1, flag2, flag3));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="项目状态转换", notes="项目状态转换")
	@PostMapping("/convertStatus")
	public AjaxJson convertStatus(String projectId, String operation){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.convertStatus(projectId, operation));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="查询金融项目的商业企划书信息", notes="查询金融项目的商业企划书信息")
	@PostMapping("/findPersonalFinanceProjectPartOne")
	public AjaxJson findPersonalFinanceProjectPartOne(String projectId){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectPartOne(projectId));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="查询金融项目的融资信息", notes="查询金融项目的融资信息")
	@PostMapping("/findPersonalFinanceProjectPartTwo")
	public AjaxJson findPersonalFinanceProjectPartTwo(String projectId){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectPartTwo(projectId));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="PC端查询项目详情", notes="PC端查询项目详情")
	@PostMapping("/findPersonalFinanceProjectDetailsOnPC")
	public AjaxJson findPersonalFinanceProjectDetailsOnPC(String personalUserId,String projectId){
		AjaxJson ajaxJson=new AjaxJson();
		if(personalUserId == null || personalUserId.trim().length() == 0){
			//若personalUserId为空，则为游客点击浏览详情
			return findPersonalFinanceProjectForPCVisitorById(projectId);
		}else{
			//若有persoanlUserId，则为用户点击浏览详情
			return findPersonalFinanceProjectDetails(projectId);
		}
	}
	
	@ApiOperation(value="查询金融项目详细信息、项目方名片，即创始人信息", notes="查询金融项目详细信息、项目方名片，即创始人信息")
	@PostMapping("/findPersonalFinanceProjectDetails")
	public AjaxJson findPersonalFinanceProjectDetails(String projectId){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectDetails(projectId));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="根据id查询PC端游客浏览金融服务VO", notes="根据id查询PC端游客浏览金融服务VO")
	@PostMapping("/findPersonalFinanceProjectForPCVisitorById")
	public AjaxJson findPersonalFinanceProjectForPCVisitorById(String projectId){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectForPCVisitorById(projectId));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="分页查询PC端游客浏览金融服务VO", notes="分页查询PC端游客浏览金融服务VO")
	@PostMapping("/findPersonalFinanceProjectForPCVisitor")
	public AjaxJson findPersonalFinanceProjectForPCVisitor(String industryField, BigDecimal financingTargetBegin, BigDecimal financingTargetEnd, String sortBy, String strategy, Integer page, Integer size){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectForPCVisitor(industryField, financingTargetBegin, financingTargetEnd, sortBy, strategy, page, size));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="分页查询APP端个人中心已发布金融服务VO", notes="分页查询APP端个人中心已发布金融服务VO")
	@PostMapping("/findPersonalFinanceProjectForAPPPerson")
	public AjaxJson findPersonalFinanceProjectForAPPPerson(String userId, Integer status, Integer page, Integer size){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectForAPPPerson(userId, status, page, size));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="APP端查询项目详情", notes="查询APP端查询项目详情")
	@PostMapping("/findPersonalFinanceProjectDetailsOnAPP")
	public AjaxJson findPersonalFinanceProjectDetailsOnAPP(String personalUserId,String projectId){
		AjaxJson ajaxJson=new AjaxJson();
		if(personalUserId == null || personalUserId.trim().length() == 0){
			//若personalUserId为空，则为游客点击浏览详情
			return findPersonalFinanceProjectForAPPVisitorById(projectId);
		}else{
			//若有persoanlUserId，则为用户点击浏览详情
			return findPersonalFinanceProjectDetails(projectId);
		}
	}
	
	@ApiOperation(value="根据id查询APP端游客浏览金融服务VO", notes="根据id查询APP端游客浏览金融服务VO")
	@PostMapping("/findPersonalFinanceProjectForAPPVisitorById")
	public AjaxJson findPersonalFinanceProjectForAPPVisitorById(String projectId){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectForAPPVisitorById(projectId));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="分页查询APP端游客浏览金融服务VO", notes="分页查询APP端游客浏览金融服务VO")
	@PostMapping("/findPersonalFinanceProjectForAPPVisitor")
	public AjaxJson findPersonalFinanceProjectForAPPVisitor(Integer page, Integer size){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findPersonalFinanceProjectForAPPVisitor(page, size));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="查询金融项目被拒绝原因", notes="查询金融项目被拒绝原因")
	@PostMapping("/findRefuseReason")
	public AjaxJson findRefuseReason(String projectId){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.findRefuseReason(projectId));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="上传金融服务项目图片，并返回url地址", notes="上传金融服务项目图片，并返回url地址")
	@PostMapping("/uploadPersonalFinanceProjectPhoto")
	public AjaxJson uploadPersonalFinanceProjectPhoto(MultipartFile projectPhoto){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.uploadPersonalFinanceProjectPhoto(projectPhoto));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="上传金融服务项目企划书，并返回url地址", notes="上传金融服务项目企划书，并返回url地址")
	@PostMapping("/uploadPersonalFinanceProjectProspectus")
	public AjaxJson uploadPersonalFinanceProjectProspectus(MultipartFile prospectus){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.uploadPersonalFinanceProjectProspectus(prospectus));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="上传金融服务项目合伙人头像，并返回url地址", notes="上传金融服务项目合伙人头像，并返回url地址")
	@PostMapping("/uploadPersonalFinanceProjectPartnerPhoto")
	public AjaxJson uploadPersonalFinanceProjectPartnerPhoto(MultipartFile photo){
		AjaxJson ajaxJson=new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(personalFinanceProjectService.uploadPersonalFinanceProjectPartnerPhoto(photo));
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
}
